let arr = [1, 2, 4, 4, 3, 3, 1, 5, 3]

const res = [
  ...new Set(arr.filter((e, idx, arr) => arr.findIndex((m) => m === e) !== idx))
]
console.log(res)

const solution = (arr) => {
  const result = []
  const hash = {}
  arr.forEach((e) => {
    if (e in hash && !result.includes(e)) {
      result.push(e)
    } else {
      hash[e] = 1
      // console.log(hash)
    }
  })
  return result
}

console.log(solution(arr))
